package com.xinqi.config;

import com.xinqi.task.LikeTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail quartzDetail_1(){
        // withIdentity指定的是这个job的id
        return JobBuilder.newJob(LikeTask.class)
                .withIdentity("LikeTask_TASK_IDENTITY")
                .storeDurably()
                .build();
    }
    @Bean
    public Trigger quartzTrigger_1(){ //触发器
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(60 * 30)  //设置时间周期单位秒
//                .withIntervalInHours(2)  //两个小时执行一次
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(quartzDetail_1())
//                .forJob(quartzDetail_2())
                .withIdentity("LikeTask_TRENDS_TRIGGER")
                .withSchedule(scheduleBuilder)
                .build();
    }

}